package com.wz.device.controller;


import com.wz.device.entity.BasCargoSpace;
import com.wz.device.service.BasCargoSpaceService;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.system.post.service.IPostService;
import com.wz.project.system.role.service.IRoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qiqi
 * @since 2021-10-22
 */
@Controller
@RequestMapping("/device/basCargoSpace")
public class BasCargoSpaceController extends BaseController {

    private String prefix = "device/basCargoSpace";

    @Autowired
    private BasCargoSpaceService basCargoSpaceService;
    @Autowired
    private IRoleService roleService;

    @Autowired
    private IPostService postService;


//    @RequiresPermissions("device:cargoSpace:view")
    @GetMapping()
    public String user() {
        return prefix + "/basCargoSpace";
    }

    @GetMapping("/selectCargoSpace")
    public String selectCargoSpace()
    {
        return  "/stock/stock/selectCargoSpace";
    }

    @GetMapping("/selectCargoSpaceByWid")
    public String selectCargoSpace(String status,String warehouseId ,ModelMap mmp)
    {
        mmp.put("status",status);
        mmp.put("warehouseId",warehouseId);
        return  "/stock/stock/selectCargoSpace";
    }


    /**
     * 设备库房区域信息列表
     * @param basCargoSpace
     * @return
     */
//    @RequiresPermissions("device:cargoSpace:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasCargoSpace basCargoSpace){
        startPage();
        List<BasCargoSpace> list = basCargoSpaceService.selectBasCargoSpaceList(basCargoSpace);
        return getDataTable(list);
    }


    /**
     * 新增设备库房信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 设备库房增加
     * @param basCargoSpace
     * @return
     */
    @RequiresPermissions("device:cargoSpace:add")
    @Log(title = "设备库房管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated BasCargoSpace basCargoSpace)
    {
        return new AjaxResult(AjaxResult.Type.SUCCESS,basCargoSpaceService.insertBasCargoSpace(basCargoSpace));
    }

    /**
     * 修改设备库房信息
     */
    @RequiresPermissions("device:cargoSpace:edit")
    @GetMapping("/edit/{cargo_space_id}")
    public String edit(@PathVariable("cargo_space_id") String cargo_space_id, ModelMap mmap)
    {
        mmap.put("cargo_space", basCargoSpaceService.selectBasCargoSpaceById(cargo_space_id));
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("device:cargoSpace:edit")
    @Log(title = "设备库房管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated BasCargoSpace basCargoSpace)
    {
        return toAjax(basCargoSpaceService.updateBasCargoSpace(basCargoSpace));

    }


    @RequiresPermissions("device:cargoSpace:remove")
    @Log(title = "设备库房管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basCargoSpaceService.deleteCargoSpaceByIds(ids));
    }

    /**
     * 设备库房是否锁定修改
     */
    @Log(title = "设备库房管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("device:cargoSpace:edit")
    @PostMapping("/changeLocked")
    @ResponseBody
    public AjaxResult changeLocked(BasCargoSpace basCargoSpace)
    {
        return toAjax(basCargoSpaceService.changeLocked(basCargoSpace));
    }

}
